﻿using System;
using System.Collections.Generic;
using System.Text;
using AspNetCs.IDAL;
using System.Collections;
using AspNetCs.Common;
using AspNetCs.Config;
using System.Data;
using AspNetCs.Model;
namespace AspNetCs.SQLServerDAL
{
    public class Memorial_DAL : IMemorial
    {
        #region IMemorial 成员

        /// <summary>
        /// 生成随机数
        /// </summary>
        /// <param name="list"></param>
        /// <param name="Rndlen"></param>
        /// <returns></returns>
        public string RndNum(ArrayList list, int Rndlen)
        {

            string Rnd = StringHelper.RndNum(Rndlen);
            for (int i = 0; i < list.Count; i++)
            {
                if (Rnd == list[i].ToString())
                {

                    Rnd = StringHelper.RndNum(Rndlen);
                    i = -1;
                }
            }
            db Conn = new db();
            try
            {

                int IsRndObj = (int)Conn.GetOneFile("Select  Count(id) from  memorial  where  Numid='" + Rnd + "'");
                if (IsRndObj != 0)
                {
                    Rnd = RndNum(list, Rndlen);
                }

            }
            catch (Exception Ex)
            {
                new CustomException(Ex);
                Rnd = "0";
            }
            finally
            {



            }

            return Rnd;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileter"></param>
        /// <returns></returns>
        public DataTable GetDataTable(string fileter)
        {
            DataTable dt = new DataTable();
            db Conn = new db();
            try
            {
                dt = Conn.GetSql_DataTable("Select * from memorial " + fileter);
            }
            finally
            {
                Conn.close();
            }
            return dt;
        }


        /// <summary>
        /// 添加纪念馆
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(memorial_model model)
        {
            int Result = 0;
            try
            {

                db.ParameterArry[] par = new db.ParameterArry[52];

                par[0].dbType = SqlDbType.VarChar;
                par[0].objValue = model.NumId;
                par[0].parName = "@NumId";

                par[1].dbType = SqlDbType.VarChar;
                par[1].objValue = model.Names;
                par[1].parName = "@Names";
                #region 用户一

                par[2].dbType = SqlDbType.VarChar;
                par[2].objValue = model.Surname;
                par[2].parName = "@Surname";

                par[3].dbType = SqlDbType.VarChar;
                par[3].objValue = model.UserName;
                par[3].parName = "@UserName";

                par[4].dbType = SqlDbType.VarChar;
                par[4].objValue = model.OtherName;
                par[4].parName = "@OtherName";

                par[5].dbType = SqlDbType.VarChar;
                par[5].objValue = model.Picture;
                par[5].parName = "@Picture";

                par[6].dbType = SqlDbType.VarChar;
                par[6].objValue = model.Sex;
                par[6].parName = "@Sex";


                par[7].dbType = SqlDbType.VarChar;
                par[7].objValue = model.DepartType_Two;
                par[7].parName = "@DepartType_Two";

                par[8].dbType = SqlDbType.VarChar;
                par[8].objValue = model.Nation;
                par[8].parName = "@Nation";

                par[9].dbType = SqlDbType.VarChar;
                par[9].objValue = model.Place;
                par[9].parName = "@Place";

                par[10].dbType = SqlDbType.VarChar;
                par[10].objValue = model.Occupation;
                par[10].parName = "@Occupation";

                par[11].dbType = SqlDbType.VarChar;
                par[11].objValue = model.Belief;
                par[11].parName = "@Belief";

                par[12].dbType = SqlDbType.VarChar;
                par[12].objValue = model.Birthday;
                par[12].parName = "@Birthday";

                par[13].dbType = SqlDbType.VarChar;
                par[13].objValue = model.LunarCalendar_Birth;
                par[13].parName = "@LunarCalendar_Birth";

                par[14].dbType = SqlDbType.VarChar;
                par[14].objValue = model.DepartTime;
                par[14].parName = "@DepartTime";

                par[15].dbType = SqlDbType.VarChar;
                par[15].objValue = model.LunarCalendar_depart;
                par[15].parName = "@LunarCalendar_depart";

                #endregion
                #region 用户二

                par[16].dbType = SqlDbType.VarChar;
                par[16].objValue = model.Surname_two;
                par[16].parName = "@Surname_two";

                par[17].dbType = SqlDbType.VarChar;
                par[17].objValue = model.UserName_two;
                par[17].parName = "@UserName_two";

                par[18].dbType = SqlDbType.VarChar;
                par[18].objValue = model.OtherName_two;
                par[18].parName = "@OtherName_two";


                par[19].dbType = SqlDbType.VarChar;
                par[19].objValue = model.Picture_two;
                par[19].parName = "@Picture_two";

                par[20].dbType = SqlDbType.VarChar;
                par[20].objValue = model.Sex_two;
                par[20].parName = "@Sex_two";

                par[21].dbType = SqlDbType.VarChar;
                par[21].objValue = model.Nation_two;
                par[21].parName = "@Nation_two";

                par[22].dbType = SqlDbType.VarChar;
                par[22].objValue = model.Place_two;
                par[22].parName = "@Place_two";

                par[23].dbType = SqlDbType.VarChar;
                par[23].objValue = model.Occupation_two;
                par[23].parName = "@Occupation_two";

                par[24].dbType = SqlDbType.VarChar;
                par[24].objValue = model.Belief_two;
                par[24].parName = "@Belief_two";

                par[25].dbType = SqlDbType.VarChar;
                par[25].objValue = model.Birthday_two;
                par[25].parName = "@Birthday_two";

                par[26].dbType = SqlDbType.VarChar;
                par[26].objValue = model.LunarCalendar_Birth_two;
                par[26].parName = "@LunarCalendar_Birth_two";

                par[27].dbType = SqlDbType.VarChar;
                par[27].objValue = model.DepartTime_two;
                par[27].parName = "@DepartTime_two";

                par[28].dbType = SqlDbType.VarChar;
                par[28].objValue = model.LunarCalendar_depart_two;
                par[28].parName = "@LunarCalendar_depart_two";

                #endregion
                par[29].dbType = SqlDbType.Int;
                par[29].objValue = model.IsEncrypt;
                par[29].parName = "@IsEncrypt";

                par[30].dbType = SqlDbType.VarChar;
                par[30].objValue = model.GetPwd;
                par[30].parName = "@GetPwd";

                par[31].dbType = SqlDbType.Text;
                par[31].objValue = model.ReadMe;
                par[31].parName = "@ReadMe";

                par[32].dbType = SqlDbType.Int;
                par[32].objValue = model.CreateId;
                par[32].parName = "@CreateId";

                par[33].dbType = SqlDbType.Int;
                par[33].objValue = model.Province;
                par[33].parName = "@province";

                par[34].dbType = SqlDbType.Int;
                par[34].objValue = model.City;
                par[34].parName = "@city";

                par[35].dbType = SqlDbType.Int;
                par[35].objValue = model.Hot;
                par[35].parName = "@Hot";

                par[36].dbType = SqlDbType.Int;
                par[36].objValue = model.Memorial_Type;
                par[36].parName = "@Memorial_Type";

                par[37].dbType = SqlDbType.DateTime;
                par[37].objValue = model.Addtime;
                par[37].parName = "@Addtime";

                par[38].dbType = SqlDbType.VarChar;
                par[38].objValue = model.NetIp;
                par[38].parName = "@NetIp";

                par[39].dbType = SqlDbType.Int;
                par[39].objValue = model.IsCheck;
                par[39].parName = "@IsCheck";

                par[40].dbType = SqlDbType.Int;
                par[40].objValue = model.IsWelfare;
                par[40].parName = "@IsWelfare";

                par[41].dbType = SqlDbType.Int;
                par[41].objValue = model.IsCommend;
                par[41].parName = "@IsCommend";

                par[42].dbType = SqlDbType.Int;
                par[42].objValue = model.Ishot;
                par[42].parName = "@IsHot";

                par[43].dbType = SqlDbType.Int;
                par[43].objValue = model.MusicId;
                par[43].parName = "@MusicId";

                par[44].dbType = SqlDbType.Int;
                par[44].objValue = model.IsDel;
                par[44].parName = "@IsDel";

                par[45].dbType = SqlDbType.Int;
                par[45].objValue = model.IsIndexTop;
                par[45].parName = "@IsIndexTop";

                par[46].dbType = SqlDbType.DateTime;
                par[46].objValue = model.IndexTop_Begintime;
                par[46].parName = "@IndexTop_BeginTime";

                par[47].dbType = SqlDbType.VarChar;
                par[47].objValue = model.BirthType_Two;
                par[47].parName = "@BirthType_Two";

                par[48].dbType = SqlDbType.DateTime;
                par[48].objValue = model.IndexTop_Endtime;
                par[48].parName = "@IndexTop_EndTime";

                par[49].dbType = SqlDbType.Int;
                par[49].objValue = model.TempleId;
                par[49].parName = "@TempleId";


                par[50].dbType = SqlDbType.VarChar;
                par[50].objValue = model.BirthType;
                par[50].parName = "@BirthType";

                par[51].dbType = SqlDbType.VarChar;
                par[51].objValue = model.DepartType;
                par[51].parName = "@DepartType";





                string Sqlstr = "insert into memorial(Numid,[names],surname,username,otherName,picture,Sex,nation,place,Occupation,belief,birthday,lunarCalendar_birth,departTime,lunarCalendar_depart,surname_Two,username_Two,otherName_Two,picture_Two,Sex_Two,nation_Two,place_Two,Occupation_Two,belief_Two,birthday_Two,lunarCalendar_birth_Two,departTime_Two,lunarCalendar_depart_Two,IsEncrypt,GetPwd,Readme,CreateId,province,city,hot,memorial_Type,Addtime,NetIp,IsCheck,IsWelfare,IsCommend,IsHot,MusicId,IsDel,IsIndexTop,IndexTop_BeginTime,IndexTop_EndTime,TempleId,birthType,departType,birthType_Two,departType_Two)";
                // Sqlstr += " values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}','{27}',{28},'{29}','{30}',{31},{32},{33},{34},{35},'{36}','{37}',{38},{39},{40},{41},{42},{43},{44},'{45}','{46}',{47},'{48}','{49}','{50}','{51}')";
                Sqlstr += " values({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25},{26},{27},{28},{29},{30},{31},{32},{33},{34},{35},{36},{37},{38},{39},{40},{41},{42},{43},{44},{45},{46},{47},{48},{49},{50},{51})";

                Sqlstr = string.Format(Sqlstr,
                    par[0].parName,
                    par[1].parName,
                    par[2].parName,
                    par[3].parName,
                    par[4].parName,
                    par[5].parName,
                    par[6].parName,
                    par[8].parName,
                    par[9].parName,
                    par[10].parName,
                    par[11].parName,
                    par[12].parName,
                    par[13].parName,
                    par[14].parName,
                    par[15].parName,
                    par[16].parName,
                    par[17].parName,
                    par[18].parName,
                    par[19].parName,
                    par[20].parName,
                    par[21].parName,
                    par[22].parName,
                    par[23].parName,
                    par[24].parName,
                    par[25].parName,
                    par[26].parName,
                    par[27].parName,
                    par[28].parName,
                    par[29].parName,
                    par[30].parName,
                    par[31].parName,
                    par[32].parName,
                    par[33].parName,
                    par[34].parName,
                    par[35].parName,
                    par[36].parName,
                    par[37].parName,
                    par[38].parName,
                    par[39].parName,
                    par[40].parName,
                    par[41].parName,
                    par[42].parName,
                    par[43].parName,
                    par[44].parName,
                    par[45].parName,
                    par[46].parName,
                    par[48].parName,
                    par[49].parName,
                    par[50].parName,
                    par[51].parName,
                    par[47].parName,
                    par[7].parName
                   );

                db Conn = new db();
                Result = Conn.ExcSql(Sqlstr, par);
                Conn.close();
            }
            catch (Exception ex)
            {
                new CustomException(ex);
                Result = -1;
            }

            return Result;
        }


        /// <summary>
        /// 在线追思
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int IndexOnTop(memorial_model model)
        {
            int Result = -1;

            db.ParameterArry[] par = new db.ParameterArry[6];
            par[0].dbType = SqlDbType.Int;
            par[0].parName = "@id";
            par[0].objValue = model.Id;

            par[1].dbType = SqlDbType.Int;
            par[1].parName = "@IsIndexTop";
            par[1].objValue = model.IsIndexTop;

            par[2].dbType = SqlDbType.DateTime;
            par[2].parName = "@Begintime";
            par[2].objValue = model.IndexTop_Begintime;

            par[3].dbType = SqlDbType.DateTime;
            par[3].parName = "@Endtime";
            par[3].objValue = model.IndexTop_Endtime;

            par[4].dbType = SqlDbType.Int;
            par[4].parName = "@CreateId";
            par[4].objValue = model.CreateId;

            par[5].dbType = SqlDbType.Int;
            par[5].parName = "@point";
            par[5].objValue = model.Hot;//暂时用来存放扣除的点数


            string Sqlstr = "begin tran";
            Sqlstr += " Update memorial Set IsIndexTop={0},IndexTop_Begintime={1},IndexTop_Endtime={2} where id={3} ";
            Sqlstr += " Update Users Set userpoint=userpoint-{4}  where Userid={5}";
            Sqlstr += " Insert into point_log(point,NetIp,UserId,Readme) values({6},'" + StringHelper.Ip() + "',{7},'纪念馆" + model.NumId + "申请在线追思,开始时间:" + model.IndexTop_Begintime + "结束时间:" + model.IndexTop_Begintime + "') ";
            //TODO:2009-10-22
            Sqlstr += "commit tran";
            Sqlstr = string.Format(Sqlstr, par[1].parName, par[2].parName, par[3].parName, par[0].parName, par[5].parName, par[4].parName,
                par[5].parName, par[4].parName
                );
            db Conn = new db();
            try
            {
                Result = Conn.ExcSql(Sqlstr, par);
            }
            finally
            {

            }
            Conn.close();

            return Result;
        }


        public memorial_model GetModel(DataRow dr)
        {
            memorial_model md = new memorial_model();
            if (dr["id"] != null) md.Id = StringHelper.isNumber_int(dr["id"].ToString());
            if (dr["Numid"] != null) md.NumId = dr["Numid"].ToString();
            if (dr["names"] != null) md.Names = dr["names"].ToString();
            if (dr["surname"] != null) md.Surname = dr["surname"].ToString();
            if (dr["username"] != null) md.UserName = dr["username"].ToString();
            if (dr["otherName"] != null) md.OtherName = dr["otherName"].ToString();
            if (dr["picture"] != null) md.Picture = dr["picture"].ToString();
            if (dr["Sex"] != null) md.Sex = dr["Sex"].ToString();
            if (dr["nation"] != null) md.Nation = dr["nation"].ToString();
            if (dr["place"] != null) md.Place = dr["place"].ToString();
            if (dr["Occupation"] != null) md.Occupation = dr["Occupation"].ToString();
            if (dr["belief"] != null) md.Belief = dr["belief"].ToString();
            if (dr["birthday"] != null) md.Birthday = dr["birthday"].ToString();
            if (dr["lunarCalendar_birth"] != null) md.LunarCalendar_Birth = dr["lunarCalendar_birth"].ToString();
            if (dr["birthType"] != null) md.BirthType = dr["birthType"].ToString();
            if (dr["departTime"] != null) md.DepartTime = dr["departTime"].ToString();
            if (dr["lunarCalendar_depart"] != null) md.LunarCalendar_depart = dr["lunarCalendar_depart"].ToString();
            if (dr["departType"] != null) md.DepartType = dr["departType"].ToString();
            if (dr["surname_Two"] != null) md.Surname_two = dr["surname_Two"].ToString();
            if (dr["username_Two"] != null) md.UserName_two = dr["username_Two"].ToString();
            if (dr["otherName_Two"] != null) md.OtherName_two = dr["otherName_Two"].ToString();
            if (dr["picture_Two"] != null) md.Picture_two = dr["picture_Two"].ToString();
            if (dr["Sex_Two"] != null) md.Sex_two = dr["Sex_Two"].ToString();
            if (dr["nation_Two"] != null) md.Nation_two = dr["nation_Two"].ToString();
            if (dr["place_Two"] != null) md.Place_two = dr["place_Two"].ToString();
            if (dr["Occupation_Two"] != null) md.Occupation_two = dr["Occupation_Two"].ToString();
            if (dr["belief_Two"] != null) md.Belief_two = dr["belief_Two"].ToString();
            if (dr["birthday_Two"] != null) md.Birthday_two = dr["birthday_Two"].ToString();
            if (dr["birthType_Two"] != null) md.BirthType_Two = dr["birthType_Two"].ToString();
            if (dr["lunarCalendar_birth_Two"] != null) md.LunarCalendar_Birth_two = dr["lunarCalendar_birth_Two"].ToString();
            if (dr["departTime_Two"] != null) md.DepartTime_two = dr["departTime_Two"].ToString();
            if (dr["lunarCalendar_depart_Two"] != null) md.LunarCalendar_depart_two = dr["lunarCalendar_depart_Two"].ToString();
            if (dr["departType_Two"] != null) md.DepartType_Two = dr["departType_Two"].ToString();
            if (dr["IsEncrypt"] != null) md.IsEncrypt = StringHelper.isNumber_int(dr["IsEncrypt"].ToString());
            if (dr["GetPwd"] != null) md.GetPwd = dr["GetPwd"].ToString();
            if (dr["Readme"] != null) md.ReadMe = dr["Readme"].ToString();
            if (dr["CreateId"] != null) md.CreateId = StringHelper.isNumber_int(dr["CreateId"].ToString());
            if (dr["province"] != null) md.Province = StringHelper.isNumber_int(dr["province"].ToString());
            if (dr["city"] != null) md.City = StringHelper.isNumber_int(dr["city"].ToString());
            if (dr["hot"] != null) md.Hot = StringHelper.isNumber_int(dr["hot"].ToString());
            if (dr["memorial_Type"] != null) md.Memorial_Type = StringHelper.isNumber_int(dr["memorial_Type"].ToString());
            if (dr["Addtime"] != null) md.Addtime = StringHelper.isDatetime(dr["Addtime"].ToString());
            if (dr["NetIp"] != null) md.NetIp = dr["NetIp"].ToString();
            if (dr["IsCheck"] != null) md.IsCheck = StringHelper.isNumber_int(dr["IsCheck"].ToString());
            if (dr["IsWelfare"] != null) md.IsWelfare = StringHelper.isNumber_int(dr["IsWelfare"].ToString());
            if (dr["IsCommend"] != null) md.IsCommend = StringHelper.isNumber_int(dr["IsCommend"].ToString());
            if (dr["IsHot"] != null) md.Ishot = StringHelper.isNumber_int(dr["IsHot"].ToString());
            if (dr["MusicId"] != null) md.MusicId = StringHelper.isNumber_int(dr["MusicId"].ToString());
            if (dr["IsDel"] != null) md.IsDel = StringHelper.isNumber_int(dr["IsDel"].ToString());
            if (dr["IsIndexTop"] != null) md.IsIndexTop = StringHelper.isNumber_int(dr["IsIndexTop"].ToString());
            if (dr["IndexTop_BeginTime"] != null) md.IndexTop_Begintime = StringHelper.isDatetime(dr["IndexTop_BeginTime"].ToString());
            if (dr["IndexTop_EndTime"] != null) md.IndexTop_Endtime = StringHelper.isDatetime(dr["IndexTop_EndTime"].ToString());
            if (dr["TempleId"] != null) md.TempleId = StringHelper.isNumber_int(dr["TempleId"].ToString());
            return md;
        }


        /// <summary>
        /// 纪念馆地址
        /// </summary>
        /// <param name="md"></param>
        /// <returns></returns>
        public int MemorialPwd_Set(memorial_model md)
        {
            int Result = -1;

            db.ParameterArry[] par = new db.ParameterArry[3];
            par[0].dbType = SqlDbType.Int;
            par[0].parName = "@id";
            par[0].objValue = md.Id;

            par[1].dbType = SqlDbType.Int;
            par[1].parName = "@IsEncrypt";
            par[1].objValue = md.IsEncrypt;

            par[2].dbType = SqlDbType.VarChar;
            par[2].parName = "@GetPwd";
            par[2].objValue = md.GetPwd;

            db Conn = new db();
            string sqlstr = "Update memorial set IsEncrypt={0},GetPwd={1} where id={2} ";
            sqlstr = string.Format(sqlstr, par[1].parName, par[2].parName, par[0].parName);

            Result = Conn.ExcSql(sqlstr, par);

            return Result;
        }


        public int Update(memorial_model model)
        {
            int Result = 0;
            try
            {
                db.ParameterArry[] par = new db.ParameterArry[36];

                par[0].dbType = SqlDbType.Int;
                par[0].objValue = model.Id;
                par[0].parName = "@id";

                par[1].dbType = SqlDbType.VarChar;
                par[1].objValue = model.Names;
                par[1].parName = "@Names";


                par[2].dbType = SqlDbType.VarChar;
                par[2].objValue = model.Surname;
                par[2].parName = "@Surname";

                par[3].dbType = SqlDbType.VarChar;
                par[3].objValue = model.UserName;
                par[3].parName = "@UserName";

                par[4].dbType = SqlDbType.VarChar;
                par[4].objValue = model.OtherName;
                par[4].parName = "@OtherName";

                par[5].dbType = SqlDbType.VarChar;
                par[5].objValue = model.Picture;
                par[5].parName = "@Picture";

                par[6].dbType = SqlDbType.VarChar;
                par[6].objValue = model.Sex;
                par[6].parName = "@Sex";


                par[7].dbType = SqlDbType.VarChar;
                par[7].objValue = model.DepartType_Two;
                par[7].parName = "@DepartType_Two";

                par[8].dbType = SqlDbType.VarChar;
                par[8].objValue = model.Nation;
                par[8].parName = "@Nation";

                par[9].dbType = SqlDbType.VarChar;
                par[9].objValue = model.Place;
                par[9].parName = "@Place";

                par[10].dbType = SqlDbType.VarChar;
                par[10].objValue = model.Occupation;
                par[10].parName = "@Occupation";

                par[11].dbType = SqlDbType.VarChar;
                par[11].objValue = model.Belief;
                par[11].parName = "@Belief";

                par[12].dbType = SqlDbType.VarChar;
                par[12].objValue = model.Birthday;
                par[12].parName = "@Birthday";

                par[13].dbType = SqlDbType.VarChar;
                par[13].objValue = model.LunarCalendar_Birth;
                par[13].parName = "@LunarCalendar_Birth";

                par[14].dbType = SqlDbType.VarChar;
                par[14].objValue = model.DepartTime;
                par[14].parName = "@DepartTime";

                par[15].dbType = SqlDbType.VarChar;
                par[15].objValue = model.LunarCalendar_depart;
                par[15].parName = "@LunarCalendar_depart";


                par[16].dbType = SqlDbType.VarChar;
                par[16].objValue = model.Surname_two;
                par[16].parName = "@Surname_two";

                par[17].dbType = SqlDbType.VarChar;
                par[17].objValue = model.UserName_two;
                par[17].parName = "@UserName_two";

                par[18].dbType = SqlDbType.VarChar;
                par[18].objValue = model.OtherName_two;
                par[18].parName = "@OtherName_two";


                par[19].dbType = SqlDbType.VarChar;
                par[19].objValue = model.Picture_two;
                par[19].parName = "@Picture_two";

                par[20].dbType = SqlDbType.VarChar;
                par[20].objValue = model.Sex_two;
                par[20].parName = "@Sex_two";

                par[21].dbType = SqlDbType.VarChar;
                par[21].objValue = model.Nation_two;
                par[21].parName = "@Nation_two";

                par[22].dbType = SqlDbType.VarChar;
                par[22].objValue = model.Place_two;
                par[22].parName = "@Place_two";

                par[23].dbType = SqlDbType.VarChar;
                par[23].objValue = model.Occupation_two;
                par[23].parName = "@Occupation_two";

                par[24].dbType = SqlDbType.VarChar;
                par[24].objValue = model.Belief_two;
                par[24].parName = "@Belief_two";

                par[25].dbType = SqlDbType.VarChar;
                par[25].objValue = model.Birthday_two;
                par[25].parName = "@Birthday_two";

                par[26].dbType = SqlDbType.VarChar;
                par[26].objValue = model.LunarCalendar_Birth_two;
                par[26].parName = "@LunarCalendar_Birth_two";

                par[27].dbType = SqlDbType.VarChar;
                par[27].objValue = model.DepartTime_two;
                par[27].parName = "@DepartTime_two";

                par[28].dbType = SqlDbType.VarChar;
                par[28].objValue = model.LunarCalendar_depart_two;
                par[28].parName = "@LunarCalendar_depart_two";

                par[29].dbType = SqlDbType.Int;
                par[29].objValue = model.IsEncrypt;
                par[29].parName = "@IsEncrypt";

                par[30].dbType = SqlDbType.VarChar;
                par[30].objValue = model.GetPwd;
                par[30].parName = "@GetPwd";

                par[31].dbType = SqlDbType.Text;
                par[31].objValue = model.ReadMe;
                par[31].parName = "@ReadMe";

                par[32].dbType = SqlDbType.VarChar;
                par[32].objValue = model.DepartType;
                par[32].parName = "@DepartType";


                par[33].dbType = SqlDbType.VarChar;
                par[33].objValue = model.BirthType;
                par[33].parName = "@BirthType";


                par[34].dbType = SqlDbType.VarChar;
                par[34].objValue = model.BirthType_Two;
                par[34].parName = "@BirthType_Two";



                par[35].dbType = SqlDbType.VarChar;
                par[35].objValue = model.NetIp;
                par[35].parName = "@NetIp";



                string Sqlstr = "Update memorial Set names=@Names,surname=@surname,username=@username,otherName=@otherName,picture=@Picture,Sex=@Sex,nation=@Nation,place=@Place,Occupation=@Occupation,belief=@Place,birthday=@Birthday,lunarCalendar_birth=@LunarCalendar_Birth,departTime=@DepartTime,lunarCalendar_depart=@LunarCalendar_depart,surname_Two=@Surname_two,username_Two=@UserName_two, ";
                Sqlstr += " otherName_Two=@OtherName_two,picture_Two=@Picture_two,Sex_Two=@Sex_two,nation_Two=@Nation_two,place_Two=@Place_two,Occupation_Two=@Occupation_two,belief_Two=@Belief_two,birthday_Two=@Birthday_two,lunarCalendar_birth_Two=@LunarCalendar_Birth_two, ";
                Sqlstr += " departTime_Two=@DepartTime_two,lunarCalendar_depart_Two=@LunarCalendar_depart_two,IsEncrypt=@IsEncrypt,GetPwd=@GetPwd,Readme=@ReadMe,";
                Sqlstr += " NetIp=@NetIp,birthType=@BirthType,departType=@DepartType,birthType_Two=@BirthType_Two,departType_Two=@DepartType_Two";
                Sqlstr += "  where id=@id";

                db Conn = new db();
                Result = Conn.ExcSql(Sqlstr, par);
                Conn.close();
            }
            catch (Exception ex)
            {
                new CustomException(ex);
                Result = -1;
            }

            return Result;








        }


        public int UserDel(string filter)
        {
            int result = -1;
            db Cn = new db();
            result = Cn.ExcSql("Update memorial Set isdel=1  where " + filter);
            Cn.close();
            return result;
        }

        public int Del(string filter)
        {
            int result = -1;
            db Cn = new db();
            result = Cn.ExcSql("delete from  memorial  where " + filter);
            Cn.close();
            return result;
        }


        /// <summary>
        /// 设置推荐或者取消推荐
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="CancleOrIntro">1表示设置推荐 0表示取消推荐</param>
        /// <returns></returns>
        public int SetIntro(int Id, int CancleOrIntro)
        {
            int count = 0;
            string cmdText = "update memorial set IsCommend=@IsCommend where id=@id";
            db.ParameterArry[] paras = new db.ParameterArry[2];
            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@IsCommend";
            paras[0].objValue = CancleOrIntro;

            paras[1].dbType = SqlDbType.Int;
            paras[1].parName = "@id";
            paras[1].objValue = Id;

            db dbclass = new db();
            count = dbclass.ExcSql(cmdText, paras);

            return count;
        }

        /// <summary>
        /// 审核或者取消审核
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="CancleOrIntro">1表示审核 0表示取消审核</param>
        /// <returns></returns>
        public int SetCheck(int Id, int CancleOrIntro)
        {
            int count = 0;
            string cmdText = "update memorial set IsCheck=@IsCheck where id=@id";
            db.ParameterArry[] paras = new db.ParameterArry[2];
            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@IsCheck";
            paras[0].objValue = CancleOrIntro;

            paras[1].dbType = SqlDbType.Int;
            paras[1].parName = "@id";
            paras[1].objValue = Id;

            db dbclass = new db();
            count = dbclass.ExcSql(cmdText, paras);

            return count;
        }

        /// <summary>
        /// 设置在线追思或者取消
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="CancleOrIntro">1表示设置在线追思 0表示取消</param>
        /// <returns></returns>
        public int SetOnlineSign(int Id, int CancleOrIntro)
        {
            int count = 0;
            string cmdText = "update memorial set IsIndexTop=@IsIndexTop where id=@id";
            db.ParameterArry[] paras = new db.ParameterArry[2];
            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@IsIndexTop";
            paras[0].objValue = CancleOrIntro;

            paras[1].dbType = SqlDbType.Int;
            paras[1].parName = "@id";
            paras[1].objValue = Id;

            db dbclass = new db();
            count = dbclass.ExcSql(cmdText, paras);

            return count;
        }

        /// <summary>
        /// 设置背景音乐
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="MusicId"></param>
        /// <returns></returns>
        public int SetMusic(int Id,int MusicId)
        {
            string cmdText = "update memorial set MusicId=@MusicId where ID=@ID";
            int count=0;
            db.ParameterArry[] paras = new db.ParameterArry[2];

            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@MusicId";
            paras[0].objValue = MusicId;

            paras[1].dbType = SqlDbType.Int;
            paras[1].parName = "@ID";
            paras[1].objValue = Id;

            db dbclass = new db();
            count = dbclass.ExcSql(cmdText,paras);
            return count;

        }

        /// <summary>
        /// 字段更新
        /// </summary>
        /// <param name="Upfilter"></param>
        /// <param name="filter"></param>
        public void filterUpdate(string Upfilter, string filter)
        {
            db Conn = new db();
            if (filter + "" != "")
            {
                filter = "  where " + filter;
            }
            Conn.Execute_Noget("update memorial Set " + Upfilter + " " + filter);
        }

        #endregion
    }
}
